// Tags:
#include <algorithm>
#include <cstdio>

typedef unsigned int uint;
const uint N = 2e5 + 5, bit = 20;
uint n, m, f[bit][N << 1], ans[N];

struct S {
  uint c, d, id;
  inline bool operator<(const S &rhs) const { return c < rhs.c; }
} ss[N << 1];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4155 [SCOI2015]国旗计划.in", "r", stdin);
  freopen("P4155 [SCOI2015]国旗计划.out", "w", stdout);
#endif
#endif

  scanf("%u%u", &n, &m);
  for (uint i = 1; i <= n; ++i) {
    scanf("%u%u", &ss[i].c, &ss[i].d);
    ss[i].id = i;
    if (ss[i].d < ss[i].c) ss[i].d += m;
    ss[i + n].c = ss[i].c + m;
    ss[i + n].d = ss[i].d + m;
    ss[i + n].id = i;
  }
  n <<= 1;
  std::sort(ss + 1, ss + n + 1);
  for (uint i = 1, j = 1; i <= n; ++i) {
    while (j <= n && ss[j].c <= ss[i].d) ++j;
    f[0][i] = j - 1;
  }
  for (uint i = 1; i < bit; ++i) {
    for (uint j = 1; j <= n; ++j) { f[i][j] = f[i - 1][f[i - 1][j]]; }
  }
  n >>= 1;
  for (uint i = 1; i <= n; ++i) {
    uint lim = ss[i].c + m, cur = i;
    for (uint j = bit - 1; ~j; --j) {
      if (f[j][cur] != 0 && ss[f[j][cur]].d < lim) {
        ans[ss[i].id] |= 1 << j;
        cur = f[j][cur];
      }
    }
  }
  for (uint i = 1; i <= n; ++i) printf("%u ", ans[i] + 2);
  return 0;
}